package com.example.graduationprojectweb.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.graduationprojectweb.common.ResponseEntity;
import com.example.graduationprojectweb.mapper.FileDao;
import com.example.graduationprojectweb.mapper.UserDao;
import com.example.graduationprojectweb.model.FilePo;
import com.example.graduationprojectweb.model.UserPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/test", method = { RequestMethod.POST })
    public ResponseEntity<Integer> test(Long account, String password, HttpServletRequest request){
        QueryWrapper<UserPo> query = new QueryWrapper<>();
        query.eq("account", account);
        query.last("limit 1");
        UserPo up = userDao.selectOne(query);
        if(up.getPassword().equals(password)){
            System.out.println("登录成功！");
            return ResponseEntity.ok(up.getId());
        }else{
            return ResponseEntity.error("账号或密码错误");
        }

    }
}
